#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<unordered_map>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],ans[maxn];
map<LL,LL>map1,map2,map3,map4;
int main(void){
    LL t;t=read();
    while(t--){
        LL n,m;n=read();m=read();
        map1.clear();map2.clear();map3.clear();map4.clear();
        for(LL i=1;i<=n;i++) a[i]=read(),map1[a[i]]++,ans[i]=0;
        LL now=0;
        bool flag=false;
        for(LL i=1;i<=n;i++){
            if(map1[a[i]]>1){
                if(!map2.count(a[i])){
                    ans[i]=1;
                    map2[a[i]]=ans[i];
                    flag=true;
                }
                else{
                    LL num=map2[a[i]];
                    ans[i]=0;
                    if(num<m){
                        ans[i]=num+1;
                        map2[a[i]]=ans[i];
                    }
                }
            }
        }
        if(!flag){
            LL k=n/m;
            LL cot=1;
            LL cnt=n-k*m;
            for(LL i=1;i<=k;i++){
                for(LL j=1;j<=m;j++){
                    cout<<j<<" ";
                }
            }
            for(LL i=1;i<=cnt;i++) cout<<"0"<<" ";
            cout<<endl;
            continue;
        }
        for(LL i=1;i<=n;i++){
            if(ans[i]!=0){
                map3[ans[i]]++;
            }
        }
        multiset<pair<LL,LL>>s;
        for(auto i:map3){
            s.insert({i.second,i.first});
        }
        for(LL i=1;i<=m;i++){
            if(!map3.count(i)) s.insert({0,i});
        }
        for(LL i=1;i<=n;i++){
            if(!ans[i]&&map1[a[i]]==1){
                auto it=(s.begin());
                LL num=(*it).first;
                ans[i]=(*it).second;
                s.erase(it);
                s.insert({num+1,ans[i]});
            }
        }
        for(LL i=1;i<=n;i++){
            if(ans[i]) map4[ans[i]]++;
        }
        LL ave=1e9;
        for(auto i:map4){
            ave=min(ave,i.second);
        }
       /// debug(ave);
        for(LL i=1;i<=n;i++){
            if(ans[i]&&map4[ans[i]]>ave){
                map4[ans[i]]--;
                ans[i]=0;
            }
        }
        for(LL i=1;i<=n;i++){
            printf("%d ",ans[i]);
        }printf("\n");
    }
   	return 0;
}
